#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

class Solution 
{
public:
	vector<vector<int> > subsetsWithDup(vector<int> & s)
	{
		// Start typing your C/C++ solution below
		// DO NOT write int main() function
		set<vector<int> > result;
		result.insert(vector<int>());

		if(s.empty())
			return vector<vector<int> >(result.begin(), result.end());

		sort(s.begin(),s.end());
		size_t n = s.size();
		vector<size_t> indexes(n);


		for(size_t k=1;k<=n;k++)
		{
			for(size_t i=1;i<=k;i++)
				indexes[i-1] = i-1;
			vector<int> tr(k);

			do
			{
				for(size_t i=1;i<=k;i++)
					tr[i-1] = s[indexes[i-1]];

				result.insert(tr);
			}while(nextCombination(indexes,n,k));
		}		

		return vector<vector<int> >(result.begin(), result.end());
	}

private:
	bool nextCombination(vector<size_t>& indexes,size_t n, size_t k)
	{
		size_t i;
		for(i = k-1;i!=-1;i--)
		{
			if(indexes[i] < (n-k+i))
			{
				break;
			}
		}

		if(i==-1)
			return false;
		indexes[i]++;
		for(size_t j=i+1;j<k;j++)
			indexes[j] = indexes[i] + j-i;

		return true;
	}
};

int main()
{
	int n;
	Solution s;
	while(cin>>n)
	{
		if(n<=0)
			break;
		vector<int> nums(n);
		for(int i=0;i<n;i++)
			cin>>nums[i];
		vector<vector<int> > r = s.subsetsWithDup(nums);

		for(size_t i=0;i<r.size();i++)
		{
			for(size_t j=0;j<r[i].size();j++)
				cout<<r[i][j]<<" ";
			cout<<endl;
		}
	}
}